<?php
/**
 * 前台文章控制器
 */
class ArticleAction extends CommonAction {

	protected $currentModel=null;
	protected $cacheCategoryData=null;

	public function _initialize()
	{
		parent::_initialize();
		$this->currentModel = D(MODULE_NAME);
		$this->cacheCategoryData=get_cache('Category');
	} 

	public function index()
	{
		$id=$this->_get($this->currentModel->getPk());
		if(!isset($id)||!is_numeric($id)){$this->error('非法操作','/');}
		$data=$this->currentModel->relation(true)->find($id);
	  	if(empty($data))
	  	{
		  $this->error('数据不存在','/');
	  	}
    	$seo=seo($data);
    	$comment=M('Comment')->where(array('value_id'=>$id,'status'=>1,'source'=>'Article'))->order('id DESC')->select();
    	$comment=$this->childComment($comment);
    	$this->upHit('Article',$data['id']);
    	$this->assign('tags',$this->getAboutTag($data['id']));
    	$this->assign('seo',$seo);
    	$this->assign('data',$data);
    	$this->assign('comment',$comment);
    	$this->assign('tplName',$this->fetch($data['tpl']));
    	$this->assign('categoryInfo',$this->cacheCategoryData[$data['category_id']]);
    	$this->assign('prevInfo',$this->getPrevInfo('Article',$data['id']));
    	$this->assign('nextInfo',$this->getNextInfo('Article',$data['id']));
        $this->display();
	}

}